package com.tenglong.teacher.ui.common.view;

import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.cuotibao.zhuoxiao.basics.utils.DensityUtil;
import com.tenglong.teacher.R;

/**
 * @author hdx on 2019/3/28.
 */
public class SlideDialog extends PopupWindow implements View.OnClickListener {

    private Context mContext;
    private SlideDialogListener listener;

    /**
     * <p>Create a new empty, non focusable popup window of dimension (0,0).</p>
     *
     * <p>The popup does provide a background.</p>
     */
    public SlideDialog(Context context) {
        super(context);
        this.mContext = context;
        init();

    }

    private void init() {
        setHeight(DensityUtil.dp2px(100));
        setWidth(DensityUtil.dp2px(125));
        setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
        setFocusable(true);
        setOutsideTouchable(false);
        initView();
    }

    private void initView() {
        ViewGroup rootView = (ViewGroup) LayoutInflater.from(mContext).inflate(R.layout.main_home_slide_dialog, null);
        rootView.findViewById(R.id.createClass).setOnClickListener(this);
        rootView.findViewById(R.id.createOneToOne).setOnClickListener(this);
        setContentView(rootView);
    }
    public void setSlideDialogListener(SlideDialogListener listener){
        this.listener = listener;
    }

    @Override
    public void onClick(View v) {
        if (listener!=null){
            listener.onSlideDialogListener(((TextView)v).getText().toString().trim());
        }
        dismiss();
    }

    public interface SlideDialogListener{
        void onSlideDialogListener(String text);
    }
}
